﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Boggle
{
    public partial class Game
    {
        private class SetupState : IGameState
        {
            private readonly Game game;

            public SetupState(Game game)
            {
                if (game == null)
                {
                    throw new ArgumentNullException("game");
                }

                this.game = game;
            }

            public void Initialize()
            {   
            }

            public void Start(DateTime currentTime)
            {
				game.Words.Clear();
                game.grid.Shuffle();
                game.CurrentWord = String.Empty;
                game.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Grid"));
                game.startedTime = currentTime;
                game.currentTime = currentTime;
                game.expectedEndTime = currentTime + game.GameLength;
                game.UpdateSecondsLeft();
                game.SetState(GameState.InProgress);
            }

            public Boolean Next(DateTime currentTime)
            {
                throw new InvalidOperationException("Cannot advance a game that has not begun");
            }

            public void SubmitWord()
            {
                throw new InvalidOperationException("Cannot submit a word before the game has begun");
            }

            public void EndGame()
            {
                throw new InvalidOperationException("Cannot end a game before the game has begun");
            }

            public void NewGame()
            {
                throw new InvalidOperationException("Cannot create a new game whilst this one is being set up");
            }

            public IBoggleDictionary Dictionary
            {
                get { return game.dict; }
                set 
                {
                    if (value == null)
                    {
                        throw new ArgumentNullException("value");
                    }
                    game.dict = value;
                    game.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Dictionary"));
                }
            }
        }
    }
}
